package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Dish;
import com.itheima.reggie.domain.Setmeal;
import com.itheima.reggie.service.DishService;
import com.itheima.reggie.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.security.PublicKey;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("setmeal")
public class SteamlController {

    @Autowired
    private SetmealService setmealService;

    @Autowired
    private DishService dishService;


    @GetMapping("list")
    @Cacheable(value = "setmeal",key = "#categoryId+'_'+#status")
    public ResultInfo findSetmealById(Long categoryId, Integer status) {
        List<Setmeal> setmeals = setmealService.findByCategoryAndStatus(categoryId, status);
        return ResultInfo.success(setmeals);
    }


    @GetMapping("/dish/{id}")
    @Cacheable(value = "setmeal",key = "#id")
    public ResultInfo findSteaml(@PathVariable Long id) {
        System.out.println(id);
       List<Dish> dishes=setmealService.finddish(id);
        return ResultInfo.success(dishes);
    }
}
